﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace GUI
{
    public partial class List_minimum_stock : Form
    {
        public List_minimum_stock()
        {
            InitializeComponent();
        }

        private void button_form_list_minimum_stock_print_Click(object sender, EventArgs e)
        {

            /*
            List<itn0912_2DBLayer.ModelLayer.Stock> KatInMin = new List<itn0912_2DBLayer.ModelLayer.Stock>();
            itn0912_2DBLayer.Controller.ControllerStock StockCtr = new itn0912_2DBLayer.Controller.ControllerStock();
            KatInMin = StockCtr.getStockByMin();

            richTextBox_form_list_minimum_stock.Clear();
            foreach (itn0912_2DBLayer.ModelLayer.Stock StockObj in KatInMin)
            {
                StockObj.Antal = richTextBox_form_list_minimum_stock.Text.ToString();
            }
            */


            List<itn0912_2DBLayer.ModelLayer.Stock> stockItems;
            itn0912_2DBLayer.Controller.ControllerStock ShowMinStock = new itn0912_2DBLayer.Controller.ControllerStock();
            stockItems = ShowMinStock.getStockByMin();
                        
            if (stockItems.Count != 0)
            {
                foreach (itn0912_2DBLayer.ModelLayer.Stock stockObj in stockItems)
                {
                    int sum = stockObj.Minimum - stockObj.Antal; 
                    richTextBox_form_list_minimum_stock.Text += "Der mangler " + sum + " stk af varenr: " + stockObj.ProductObj.Varenummer + "\n";
                }
            }
            else
            {
                string err = "Det er ikke nødvendigt at bestille flere varer hjem!";
                richTextBox_form_list_minimum_stock.Text = err;
            }
            /*
            List<Stock> stockItems;
            ControllerStock showMinStock = new ControllerStock();
            stockItems = showMinStock.getStockByMin();
             * // How do we convert katId to the Name? Yet to be done 
            try
            {                    
                
                if (stockItems.Count != 0)
               {
                   foreach (Stock stockObj in stockItems)
                   {
                       //Stock.bvarenr, Stock.antal, Stock.minimum, Stock.bkatId, Kategori.kategori
                       Console.WriteLine("varnr: " + stockObj.ProductObj.Varenummer.ToString() + "\r\nAntal: " + stockObj.Antal.ToString()
                           + "\r\nMinimum: " + stockObj.Minimum.ToString() + "\r\nKategori: " + stockObj.KategoriObj.FullKategori.ToString());
                   }
                    
                }
                else
                {
                    Console.WriteLine("nothing found");
                }

            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }

            */

            //richTextBox_form_list_minimum_stock.Text = "OKOKOK";
        }

        private void button_form_list_minimum_stock_exit_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void List_minimum_stock_Load(object sender, EventArgs e)
        {
            richTextBox_form_list_minimum_stock.Clear();
        }
    }
}
